class Solution:
    def minOperations(self, boxes: str) -> list[int]:
        # O(n^2) solution
        n = len(boxes)
        result = [0] * n

        for i in range(n):
            for j in range(n):
                if i != j and boxes[j] == '1':
                    result[i] += abs(i - j)
        return result

    def minOperations2(self, boxes: str) -> list[int]:
        # O(n) solution
        n = len(boxes)
        result = [0] * n

        count, operations = 0, 0
        for i in range(n):
            result[i] += operations
            if boxes[i] == '1':
                count += 1
            operations += count
        count, operations = 0, 0
        for i in range(n - 1, -1, -1):
            result[i] += operations
            if boxes[i] == '1':
                count += 1
            operations += count
        return result


a = Solution().minOperations2("001011")  # Example usage
print(a)